package cn.mdx.controller;

import cn.mdx.adminservice.AdminService;
import cn.mdx.common.beans.ResultBean;
import cn.mdx.common.beans.User;
import cn.mdx.pojo.*;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * 信息审核接口提供信息资源id和审核是否通过对应的数值，封装为对象
 * 获取详细信息接口需要提供查询资源的id值
 * 修改资源信息需要提供修改后的数据，将数据封装为对象
 * 删除接口提供删除资源信息的id值
 */
@SuppressWarnings({"ALL", "AlibabaClassMustHaveAuthor"})
@RestController
@Controller
@RequestMapping("/admin")
@CrossOrigin
public class AdminController {

    @Autowired
    private AdminService adminService;



    @PostMapping("/statistics")
    public ResultBean getBySome(HttpSession session,Integer timeClass){
        return new ResultBean( adminService.getBySome(User.getId(session),timeClass));
    }


    //分页查询专利信息
    @RequestMapping("/getAllPatent")
    public ResultBean getAllPatent(HttpSession session,Integer pageno){
        System.out.println("pageno值:"+pageno);
        PageInfo<Patent> paten=adminService.getAll(session,pageno);
        return new ResultBean(paten);
    }


    //分页查询平台资源信息    cid 院别  pageno 页面序号
    @RequestMapping("/getAllTerrace")
    public ResultBean getAllTerrace(HttpSession session,Integer pageno){
        PageInfo<Terrace> terrace=adminService.getAllTerrace(session,pageno);
        return new ResultBean(terrace);
    }


    /**
     * 分页查询团队资源信息
     * @param session
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllTeam")
    public ResultBean getAllTeam(HttpSession session,Integer pageno){
        PageInfo<Team> teamPageInfo=adminService.getAllTeam(session,pageno);
        return  new ResultBean(teamPageInfo);
    }


    /**
     * 分页查询软著资源信息
     * @param session
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllSoftware")
    public ResultBean getAllSoftware(HttpSession session,Integer pageno){
        System.out.println("pageno值:"+pageno);
        PageInfo<Software> softwarePageInfo=adminService.getAllSoftware(session,pageno);
        return new ResultBean(softwarePageInfo);
    }



    /**
     * admin用户cid信息为空
     * 查询校企资源
     * @param session
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllSchool")
    public ResultBean getAllSchool(HttpSession session,Integer pageno){
        User user=(User)session.getAttribute("user");
        PageInfo<School> schoolPageInfo=adminService.getAllSchool(user,null,pageno);
        return new ResultBean(schoolPageInfo);
    }


    /**
     * 查询全部的需求信息
     * @param session
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllDemand")
    public ResultBean getAllDemand(HttpSession session,Integer pageno){
        User user=(User) session.getAttribute("user");
        PageInfo<Demand> demandPageInfo=adminService.getAllDemand(user,pageno);
        return new ResultBean(demandPageInfo);
    }


    /**
     * 分页查询需求方信息
     * @param session
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllNeeduser")
    public ResultBean getAllNeeduser(HttpSession session,Integer pageno){
        User user=(User)session.getAttribute("user");
        PageInfo<Needuser> needusers=adminService.getAllNeeduser(user,pageno);
        return new ResultBean(needusers);
    }


    /**
     * 分页查询所有分类信息
     * @param session
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllAchievement")
    public ResultBean getAllAchievement(HttpSession session,Integer pageno){
        User user=(User)session.getAttribute("user");
        PageInfo<Achievement> achievementPageInfo=adminService.getAllAchievement(user,pageno);
        return new ResultBean(achievementPageInfo);
    }


    /**
     * 专利审核信息修改
     * @param patent
     * @return
     */
    @PostMapping("/patentToexamine")
    public ResultBean patentToexamine(Patent patent){
        System.out.println("审核pid："+patent.getPid()+"====审核值："+patent.getAudit());
        adminService.patentToexamine(patent);
        return new ResultBean();
    }

    /**
     * 获取单个专利的详细信息
     * @param pid
     * @return
     */
    @RequestMapping("/getPatentInfo")
    public ResultBean getPatentInfo(Integer pid){
        return new ResultBean(adminService.getPatentInfo(pid));
    }

    /**
     *修改专利信息
     * @param patent
     * @return
     */
  /*  @PostMapping("updataPatent")
    public ResultBean updataPatent(Patent patent){
        adminService.updataPaten(patent);
        return new ResultBean();
    }*/

    /**
     * 删除在专利信息
     * @param pid
     * @return
     */
    @PostMapping("/deletePatent")
    public ResultBean deletePatent(Integer pid){
        System.out.println("pid:"+pid);
        adminService.deletePatent(pid);
        return new ResultBean();
    }


    /**
     * 修改平台审核信息
     * @param terrace
     * @return
     */
    @PostMapping("/terraceToexamine")
    public ResultBean terraceToexamine(Terrace terrace){
        adminService.terraceToexamine(terrace);
        return new ResultBean();
    }


    /**
     * 获取平台详细信息
     * @param tid
     * @return
     */
    @PostMapping("/getTerraceInfo")
    public ResultBean getTerraceInfo(Integer tid){
        return new ResultBean(adminService.getTerraceInfo(tid));
    }


    /**
     * 修改平台相关信息
     * @param terrace
     * @return
     */
    @PostMapping("/updataTerrace")
    public ResultBean updataTerrace(Terrace terrace){
        adminService.updataTerrace(terrace);
        return new ResultBean();
    }

    /**
     * 删除平台信息
     * @param tid
     * @return
     */
    @PostMapping("/deleteTerrace")
    public ResultBean deleteTerrace(Integer tid){
        adminService.deleteTerrace(tid);
        return new ResultBean();
    }


    /**
     * 团队审核
     * @param team
     * @return
     */
    @PostMapping("/teamToexamine")
    public ResultBean teamToexamine(Team team){
        adminService.teamToexamine(team);
        return new ResultBean();
    }


    @PostMapping("/getTeamInfo")
    public ResultBean getTeamInfo(Integer tid){
        return new ResultBean(adminService.getTeamInfo(tid));
    }

    @PostMapping("/updataTeam")
    public ResultBean updataTeam(Team team){
        adminService.updataTeam(team);
        return new ResultBean();
    }



    @PostMapping("/deleteTeam")
    public ResultBean deleteTeam(Integer tid){
        adminService.deleteTeam(tid);
        return new ResultBean();
    }

//----软著


    @PostMapping("/softwareToexamine")
    public ResultBean softwareToexamine(Software software){
        adminService.softwareToexamine(software);
        return new ResultBean();
    }


    @PostMapping("/getSoftwareInfo")
    public ResultBean get(Integer sid){
        return new ResultBean(adminService.getSoftware(sid));
    }


    @PostMapping("/updataSoftware")
    public ResultBean updata(Software software){
        adminService.updataSoftware(software);
        return new ResultBean();
    }



    @PostMapping("/deleteSoftware")
    public ResultBean delete(Integer sid){
        adminService.deleteSoftware(sid);
        return new ResultBean();
    }




//------校企


    @PostMapping("/schoolToexamine")
    public ResultBean schoolToexamine(School school){
        adminService.schoolToexamine(school);
        return new ResultBean();
    }


    @PostMapping("/getSchool")
    public ResultBean getSchool(Integer sid){
        return new ResultBean(adminService.getSchool(sid));
    }


    @PostMapping("/updataSchool")
    public ResultBean updataSchool(School school){
        adminService.updataSchool(school);
        return new ResultBean();
    }



    @PostMapping("/deleteSchool")
    public ResultBean deleteSchool(Integer sid){
        adminService.deleteSchool(sid);
        return new ResultBean();
    }




//----------------技术需求

    @PostMapping("/demandToexamine")
    public ResultBean demandToexamine(Demand demand){
        adminService.demandToexamine(demand);
        return new ResultBean();
    }


    @PostMapping("/getDemand")
    public ResultBean getDemand(Integer did){
        return new ResultBean(adminService.getDemandInfo(did));
    }


    @PostMapping("/updataDemand")
    public ResultBean updata(Demand demand){
        adminService.updataDemand(demand);
        return new ResultBean();
    }



    @PostMapping("/deleteDemand")
    public ResultBean deleteDemand(Integer did){
        adminService.deleteDemand(did);
        return new ResultBean();
    }


//--------------技术需求方信息


    @PostMapping("/needuserToexamine")
    public ResultBean needuserToexamine(Needuser needuser){
        adminService.needuserToexamin(needuser);
        return new ResultBean();
    }


    @PostMapping("/getNeeduser")
    public ResultBean getNeeduser(Integer nid){
        return new ResultBean(adminService.getNeeduser(nid));
    }


    @PostMapping("/updataNeeduser")
    public ResultBean updata(Needuser needuser){
        adminService.updataNeeduser(needuser);
        return new ResultBean();
    }



    @PostMapping("/deleteNeeduser")
    public ResultBean deleteNeeduser(Integer nid){
        adminService.deleteNeeduser(nid);
        return new ResultBean();
    }



//--------------成果分类信息


    @PostMapping("/addAchievement")
    public ResultBean addAchievement(Achievement achievement){
        adminService.addAchievement(achievement);
        return new ResultBean();
    }

    @PostMapping("/getAchievement")
    public ResultBean getAchievement(Integer aid){
        return new ResultBean(adminService.getAchievement(aid));
    }


    @PostMapping("/updataAchievement")
    public ResultBean updata(Achievement achievement){
        adminService.updataAchievement(achievement);
        return new ResultBean();
    }



    @PostMapping("/deleteAchievement")
    public ResultBean deleteAchievement(Integer aid){
        adminService.deleteAchievement(aid);
        return new ResultBean();
    }


    /**
     * 获取对接成果信息
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllResult")
    public ResultBean getAllResult(Integer pageno,HttpSession session){
        System.out.println("pageno:"+pageno);
        User user=(User)session.getAttribute("user");
        PageInfo<Result> resultPageInfo=adminService.getAllResultByCid(user,null,pageno);
        System.out.println("数据量："+resultPageInfo.getSize());
        return new ResultBean(resultPageInfo);
    }

    /**
     * 修改对接成果审核信息
     * @param result
     * @return
     */
    @PostMapping("/resultToexaimn")
    public ResultBean resultToexaimn(Result result){
        adminService.resultToexaimn(result);
        return new ResultBean();
    }


    /**
     * 删除对接成果信息
     * @param rid
     * @return
     */
    @PostMapping("/deleteResult")
    public ResultBean deleteResult(Integer rid){
        adminService.deleteReslut(rid);
        return new ResultBean();
    }


    /**
     * 需要姓名  工号  所在部门
     * @param skilluser
     * @return
     */
    @PostMapping("/addSkilluser")
    public ResultBean addSkilluser(Skilluser skilluser){
        System.out.println("uid:"+skilluser.getUid()+"===cid:"+skilluser.getCid()
                +"===power:"+skilluser.getPower()+"===username"+skilluser.getUsername()
                +"===name:"+skilluser.getName()+"===password:"+skilluser.getPassword());
        adminService.addSkilluser(skilluser);
        return new ResultBean();
    }




    /**
     * 需要pageno
     * @param session
     * @param pageno
     * @return
     */
    @RequestMapping("/getAllSkilluser")
    public ResultBean getAllSkilluser(HttpSession session,Integer pageno){
        System.out.println("pageno:"+pageno);
        User user=(User) session.getAttribute("user");
        PageInfo<SkillUserVO> skilluserPageInfo=adminService.getAllSkilluser(user,pageno);
        System.out.println("数据量："+skilluserPageInfo.getSize());
        return new ResultBean(skilluserPageInfo);
    }



    /**
     * 需要审核值和技术方id
     * @param skilluser
     * @return
     */
    @PostMapping("/skilluserToexamin")
    public ResultBean skilluserToexamin(SkillUserVO skilluser){
        System.out.println(skilluser.getName()+"====审核值"+skilluser.getAudit());
        adminService.skilluserToexaimn(skilluser);
        return new ResultBean();
    }



    @PostMapping("/deleteSkilluser")
    public ResultBean deleteSkilluser(SkillUserVO skillUserVO){
        adminService.deleteSkillusers(skillUserVO);
        return new ResultBean();
    }


    @PostMapping("/getSkilluserInfo")
    public ResultBean getSkilluserByusername(HttpSession session,Skilluser skilluser,Integer pageno){
        User user=(User)session.getAttribute("user");
        PageInfo<SkillUserVO> skillUserVOPageInfo=adminService.getSkilluserByusername(skilluser,user,pageno);
        return new ResultBean(skillUserVOPageInfo);
    }

}
